#!/usr/bin/bash

# echo $#

if [ "$#" != "1" ]; then
    echo "please give a string as argument"
    exit
fi

export PATH=$PATH:/mingw64/bin

echo -ne '\e]0;MinGW x64\a'

this_pid=$$
text=$1
trans_text=$(./trans -e bing -s en -t zh -brief "${text}")

# audio="$(<kb_snd2.wav)"

./AutoHotkey64.exe increase_mintty_fontsize.ahk
reset

(
    /mingw64/bin/mpg123 --loop -1 -q r2d2_droid.mp3 # kb_snd2.mp3;
    # cat r2d2_droid.wav | nc -c 127.0.0.1 3399
    # cat kb_snd2.wav > /dev/dsp
    # ( echo "$audio"; cat - ) > /dev/dsp

) &
audio_pid=$!

(
    printf "\n\n\n\n\n"
    printf "___${text^^}___" | pv -qL 10
    printf "\r"
    printf "___${trans_text}___"  | pv -qL 10
    kill -15 $audio_pid
) &
text_pid=$!

wait $audio_pid
wait $text_pid

sleep 2
./AutoHotkey64.exe reset_mintty_fontsize.ahk

reset

